package com.css.fxfzcpxx.modules.thematicMap.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.css.fxfzcpxx.base.attachment.entity.AttachmentInfoEntity;
import com.css.fxfzcpxx.base.attachment.service.AttachmentInfoService;
import com.css.fxfzcpxx.common.utils.UpdateUtil;
import com.css.fxfzcpxx.constants.FxfzConstants;
import com.css.fxfzcpxx.constants.YNEnum;
import com.css.fxfzcpxx.modules.thematicMap.entity.AchManageEntity;
import com.css.fxfzcpxx.modules.thematicMap.entity.ThematicMap;
import com.css.fxfzcpxx.modules.thematicMap.param.Quaparams;
import com.css.fxfzcpxx.modules.thematicMap.param.QueParams;
import com.css.fxfzcpxx.modules.thematicMap.param.ZoningParams;
import com.css.fxfzcpxx.modules.thematicMap.repository.TheMapRepository;
import com.css.fxfzcpxx.modules.thematicMap.service.TheMapService;
import com.css.fxfzcpxx.modules.thematicMap.vo.ListVo;
import com.css.fxfzcpxx.modules.thematicMap.vo.OtherSystemInfoVo;
import com.css.fxfzcpxx.modules.thematicMap.vo.ThematicMapVo;
import com.css.fxfzcpxx.util.*;
import com.css.fxfzcpxx.web.PlatformSessionContext;
import com.css.fxfzcpxx.zcpt.sys.entity.SOrg;
import com.css.fxfzcpxx.zcpt.sys.entity.SUser;
import com.css.fxfzcpxx.zcpt.sys.service.SUserService;
import com.css.fxfzcpxx.zcpt.sys.service.SysAreaService;
import com.css.fxfzcpxx.zcpt.sys.service.SysOrgService;
import com.css.fxfzcpxx.zcpt.sys.service.impl.SUserServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.slw.common.helper.PropsHelper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Pattern;
@Slf4j
@Service
public class TheMapServiceImpl implements TheMapService {

    @Resource
    TheMapRepository theMapRepository;

    @Resource
    AttachmentInfoService attachmentInfoService;

    @Resource
    private SysAreaService sysAreaService;

    @Autowired
    SUserServiceImpl sUserServiceImpl;

    @Resource
    SUserService sUserService;

    @Resource
    SysOrgService sysOrgService;

    @Resource(name = "httpsRestTemplates")
    RestTemplate restTemplate;

    @Value("${image.localDir}")
    private String localDir;
    @Resource
    private RedisLockUtil redisLockUtil;

    @Override
    public Map<String, Object> getPage(QueParams queParams, int curPage, int pageSize) {
        Map<String, Object> page = theMapRepository.getPage(queParams,curPage, pageSize);
        return page;
    }

    @Override
    public void save(ThematicMap thematicMap) {
        if (PlatformObjectUtils.isEmpty(thematicMap.getFlag())){
            thematicMap.setId(UUIDGenerator.getUUID());
            thematicMap.setCreateUser(PlatformSessionContext.getUserID());
            String userId = PlatformSessionContext.getUserID();
            String user = sUserService.getSUser(userId);
            SUser sUser = CreateGson.createGson().fromJson(user, SUser.class);
            String org = sysOrgService.getOrgById(sUser.getOrgId());
            SOrg sOrg = CreateGson.createGson().fromJson(org, SOrg.class);
            thematicMap.setPublishingUnit(sOrg.getName());
            thematicMap.setFlag(YNEnum.N.toString());
            thematicMap.setNumber(getNumber("0"));
            thematicMap.setCreateTime(new Date());
            thematicMap.setDelFlag(YNEnum.N.toString());
            thematicMap.setReleaseStatus(YNEnum.Y.toString());
        }else {
            thematicMap.setNumber(getNumber("1"));
        }
        theMapRepository.save(thematicMap);
    }

    @Override
    public void recallOrPublish(QueParams queParams) {
        if("0".equals(queParams.getReleaseStatus())){
            String sUser = sUserServiceImpl.getSUser(PlatformSessionContext.getUserID());
            theMapRepository.publish(queParams.getReleaseStatus(), Arrays.asList(queParams.getIds().split(",")),new Date());
        }else{
            theMapRepository.recall(queParams.getReleaseStatus(), Arrays.asList(queParams.getIds().split(",")));
        }

    }

    @Override
    public void delete(String ids) {
        theMapRepository.delete(Arrays.asList(ids.split(",")));
    }

    @Override
    public ThematicMapVo findById(String id) {
        ThematicMapVo thematicMapVo=new ThematicMapVo();
        ThematicMap thematicMap=theMapRepository.findById(id);
        UpdateUtil.copyNullProperties(thematicMap, thematicMapVo);
        if (PlatformObjectUtils.isNotEmpty(thematicMap.getPictureFile())){
            thematicMapVo.setPictureFileAtt(attachmentInfoService.queryFile(thematicMap.getPictureFile()));
        }
        /*String province = thematicMapVo.getProvince();
        String city = thematicMapVo.getCity();
        String county = thematicMapVo.getCounty();
        if(!isChinese(province) && !PlatformObjectUtils.isEmpty(province)){
            String provinceName = sysAreaService.getAreaNameByAreaId(province);
            thematicMapVo.setProvince(provinceName);
        }
        if(!PlatformObjectUtils.isEmpty(city)&&!isChinese(city)){
            String cityName = sysAreaService.getAreaNameByAreaId(city);
            thematicMapVo.setCity(cityName);
        }
        if(!PlatformObjectUtils.isEmpty(county)&&!isChinese(county)){
            String countyName = sysAreaService.getAreaNameByAreaId(county);
            thematicMapVo.setCounty(countyName);
        }*/
        return thematicMapVo;
    }

    public static boolean isChinese(String value) {
        if (value!=null){
        Pattern pattern = Pattern.compile("[\u0391-\uFFE5]+$");
        return pattern.matcher(value).matches();
        }else {
            return false;
        }
    }


    @Override
    public List<ThematicMap> getkeywordManageData(String ids) {
        return theMapRepository.getkeywordManageData(Arrays.asList(ids.split(",")));
    }

    @Override
    public void keywordUpdate(ListVo listvo) {
        List<ThematicMap> list = listvo.getList();
        for(ThematicMap item:list){
            theMapRepository.keywordUpdate(item.getId(),item.getKeyword());
        }
    }

    @Override
    public void update(ThematicMap thematicMap) {
        thematicMap.setUpdateTime(new Date());
        thematicMap.setUpdateUser(PlatformSessionContext.getUserID());

        if("0".equals(thematicMap.getReleaseStatus())){
            theMapRepository.publishedDataupdate(thematicMap);
        }else{
            theMapRepository.unpublishedDataupdate(thematicMap);
        }
    }

    @Override
    public void catalogDownload(HttpServletResponse response, String ids) {
        List<ThematicMap> thematicMaps = this.getkeywordManageData(ids);
        if (thematicMaps.size() <= 0) {
            throw new RuntimeException("数据为空,无法导出！");
        }
        try {
            EasyPoiExcelUtil.exportExcel(thematicMaps, "专题图数据信息统计", "专题图数据信息", ThematicMap.class, "专题图数据信息", response);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public  Map<String,Object> getDataList(QueParams queParams, int curPage, int pageSize) {
        Map<String,Object> dataList = theMapRepository.getDataList(queParams,  curPage,  pageSize);
        List<ThematicMapVo> list = (List<ThematicMapVo>) dataList.get("rows");
        for (ThematicMapVo item: list) {
            if (PlatformObjectUtils.isNotEmpty(item.getPictureFile())){
                item.setPictureFileAtt(attachmentInfoService.queryFile(item.getPictureFile()));
            }
        }
        return dataList;
    }

    @Override
    public Map<String, Object> getEngineeringDistributionPage(Quaparams param, int curPage, int pageSize) {
        StringBuilder queryStr=new StringBuilder();
        if(PlatformObjectUtils.isNotEmpty(param.getEngineeringName())){
            queryStr.append("&engineeringName="+param.getEngineeringName()+"");
        }
        if(PlatformObjectUtils.isNotEmpty(param.getEngineeringCode())){
            queryStr.append("&engineeringCode="+param.getEngineeringCode()+"");
        }
        if(PlatformObjectUtils.isNotEmpty(param.getEngineeringType())){
            queryStr.append("&engineeringType="+param.getEngineeringType()+"");
        }
        if(PlatformObjectUtils.isNotEmpty(param.getStartTime())){
            queryStr.append("&startTime="+param.getStartTime()+"");
        }
        if(PlatformObjectUtils.isNotEmpty(param.getEndTime())){
            queryStr.append("&endTime="+param.getEndTime()+"");
        }
        if(PlatformObjectUtils.isNotEmpty(param.getEngineeringRange())){
            queryStr.append("&engineeringRange="+param.getEngineeringRange()+"");
        }
        if(PlatformObjectUtils.isNotEmpty(param.getProvince())){
            queryStr.append("&province="+param.getProvince()+"");
        }
        if(PlatformObjectUtils.isNotEmpty(param.getCity())){
            queryStr.append("&city="+param.getCity()+"");
        }
        if(PlatformObjectUtils.isNotEmpty(param.getCounty())){
            queryStr.append("&county="+param.getCounty()+"");
        }
        if(PlatformObjectUtils.isNotEmpty(param.getReleaseState())){
            queryStr.append("&releaseState="+param.getReleaseState()+"");
        }
        if(PlatformObjectUtils.isNotEmpty(param.getEngineeringCategory())){
            queryStr.append("&engineeringCategory="+param.getEngineeringCategory()+"");
        }

        Properties configGroup = PropsHelper.loadProps("slw-config.properties");
        String url = configGroup.getProperty("fwjgRestUrl") + "/fw/AchManage/getPage?page="+curPage+"&rows="+pageSize+"";
        JSONObject valueMap = new JSONObject();
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        headers.set("Authorization", "fxfzxczh");
        headers.set("subsystemCode", "dzxczhsspgzxt");
        HttpEntity<JSONObject> r = new HttpEntity<>(valueMap, headers);
        String url1 = new StringBuilder(url).append(queryStr).toString();
        JSONObject data = restTemplate.exchange(url1, HttpMethod.GET, r, JSONObject.class).getBody().getJSONObject("data");
        String rows = data.getString("rows");
        List<Map> list = JSON.parseObject(rows, new TypeReference<List<Map>>() {});
        Integer total = Integer.valueOf(data.getString("total"));
        Map<String, Object> page = new HashMap<>();
        page.put("total", total);
        page.put("rows", list);
        return page;
    }

    @Override
    public AchManageEntity findEngineeringById(String id) {
        Properties configGroup = PropsHelper.loadProps("slw-config.properties");
        String url = configGroup.getProperty("fwjgRestUrl") + "/fw/AchManage/findById?id="+id+"";
        JSONObject valueMap = new JSONObject();
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        headers.set("Authorization", "fxfzcpxx");
        headers.set("subsystemCode", "dzxczhsspgzxt");
        HttpEntity<JSONObject> r = new HttpEntity<>(valueMap, headers);

        JSONObject data = restTemplate.exchange(url, HttpMethod.GET, r, JSONObject.class).getBody().getJSONObject("data");

        AchManageEntity achManageEntity = JSON.parseObject(data.toJSONString(), AchManageEntity.class);

        return achManageEntity;
    }

    @Override
    public List<Map<String, Object>> getData(String ids) {
        Properties configGroup = PropsHelper.loadProps("slw-config.properties");
        String url = configGroup.getProperty("fwjgRestUrl") + "/fw/AchManage/getData?ids="+ids+"";
        JSONObject valueMap = new JSONObject();
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        headers.set("Authorization", "fxfzcpxx");
        headers.set("subsystemCode", "dzxczhsspgzxt");
        HttpEntity<JSONObject> r = new HttpEntity<>(valueMap, headers);

        JSONArray data = restTemplate.exchange(url, HttpMethod.GET, r, JSONObject.class).getBody().getJSONArray("data");
        List<Map<String, Object>> list = new ArrayList<>();
        if(data.isEmpty()){
            return  list;
        }
        for (int i = 0; i < data.size(); i++) {
            JSONObject jsonObject = data.getJSONObject(i); // 获取每个元素的 JSONObject 对象
            Map<String, Object> map = jsonObject.toJavaObject(Map.class); // 将 JSONObject 转换为 Map
            list.add(map); // 将 Map 添加到 List 中
        }
        return list;
    }

    @Override
    public Map<String, Object> getZoningRecordList(ZoningParams quaparams, int curPage, int pageSize) {
        StringBuilder queryStr=new StringBuilder();
        if(PlatformObjectUtils.isNotEmpty(quaparams.getZoningCode())){
            queryStr.append("&zoningCode="+quaparams.getZoningCode()+"");
        }
        if(PlatformObjectUtils.isNotEmpty(quaparams.getZoningName())){
            queryStr.append("&zoningName="+quaparams.getZoningName()+"");
        }

        Properties configGroup = PropsHelper.loadProps("slw-config.properties");
        String url = configGroup.getProperty("dqhRestUrl") + "/enterAssessQh/getAssessPage?page="+curPage+"&rows="+pageSize+"";
        JSONObject valueMap = new JSONObject();
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        headers.set("Authorization", "fxfzcpxx");
        headers.set("subsystemCode", "dzxczhsspgzxt");
        HttpEntity<JSONObject> r = new HttpEntity<>(valueMap, headers);
        String url1 = new StringBuilder(url).append(queryStr).toString();
        JSONObject data = restTemplate.exchange(url1, HttpMethod.GET, r, JSONObject.class).getBody().getJSONObject("data");
        String rows = data.getString("rows");
        List<Map> list = JSON.parseObject(rows, new TypeReference<List<Map>>() {});
        Integer total = Integer.valueOf(data.getString("total"));
        Map<String, Object> page = new HashMap<String, Object>();
        page.put("total", total);
        page.put("rows", list);
        return page;

    }

    @Override
    public Map<String, Object> getZoningSetting(Integer type) {
        Properties configGroup = PropsHelper.loadProps("slw-config.properties");
        String url = configGroup.getProperty("dqhRestUrl") + "/singleIndicatorRiskZoneSet/get?type="+type+"";
        JSONObject valueMap = new JSONObject();
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        headers.set("Authorization", "fxfzcpxx");
        headers.set("subsystemCode", "dzxczhsspgzxt");
        HttpEntity<JSONObject> r = new HttpEntity<>(valueMap, headers);
        JSONObject data = restTemplate.exchange(url, HttpMethod.GET, r, JSONObject.class).getBody().getJSONObject("data");
        Map map = data.toJavaObject(Map.class);
        return map;

    }

    @Override
    public List<Map<String, Object>> getEngineeringDistribution(Quaparams quaparams) {
        StringBuilder queryStr=new StringBuilder();
        if(PlatformObjectUtils.isNotEmpty(quaparams.getEngineeringType())){
            queryStr.append("?engineeringType="+quaparams.getEngineeringType()+"");
        }


        Properties configGroup = PropsHelper.loadProps("slw-config.properties");
        String url = configGroup.getProperty("fwjgRestUrl") + "/fw/AchManage/getCasebookData";
        JSONObject valueMap = new JSONObject();
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        headers.set("Authorization", "fxfzxczh");
        headers.set("subsystemCode", "dzxczhsspgzxt");
        HttpEntity<JSONObject> r = new HttpEntity<>(valueMap, headers);
        String url1 = new StringBuilder(url).append(queryStr).toString();
        JSONArray data = restTemplate.exchange(url1, HttpMethod.GET, r, JSONObject.class).getBody().getJSONArray("data");
        List<Map<String, Object>> list = new ArrayList<>();
        if(data.isEmpty()){
            return  list;
        }
        for (int i = 0; i < data.size(); i++) {
            JSONObject jsonObject = data.getJSONObject(i); // 获取每个元素的 JSONObject 对象
            Map<String, Object> map = jsonObject.toJavaObject(Map.class); // 将 JSONObject 转换为 Map
            list.add(map); // 将 Map 添加到 List 中
        }
        return list;
    }

    @Override
    public List<Map<String, Object>> getReinforceData(Quaparams param) {
        StringBuilder queryStr=new StringBuilder();
        if(PlatformObjectUtils.isNotEmpty(param.getEngineeringRange())){
            queryStr.append("?engineeringRange="+param.getEngineeringRange()+"");
        }
        if(PlatformObjectUtils.isNotEmpty(param.getEngineeringType())){
            queryStr.append("&engineeringType="+param.getEngineeringType()+"");
        }
        if(PlatformObjectUtils.isNotEmpty(param.getEngineeringRange())){
            queryStr.append("&engineeringRange="+param.getEngineeringRange()+"");
        }
        if(PlatformObjectUtils.isNotEmpty(param.getProvince())){
            queryStr.append("&province="+param.getProvince()+"");
        }
        if(PlatformObjectUtils.isNotEmpty(param.getCity())){
            queryStr.append("&city="+param.getCity()+"");
        }
        if(PlatformObjectUtils.isNotEmpty(param.getCounty())){
            queryStr.append("&county="+param.getCounty()+"");
        }

        Properties configGroup = PropsHelper.loadProps("slw-config.properties");
        String url = configGroup.getProperty("fwjgRestUrl") + "/fw/AchManage/getReinforceData?";
        JSONObject valueMap = new JSONObject();
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        headers.set("Authorization", "fxfzcpxx");
        headers.set("subsystemCode", "dzxczhsspgzxt");
        HttpEntity<JSONObject> r = new HttpEntity<>(valueMap, headers);
        String url1 = new StringBuilder(url).append(queryStr).toString();
        JSONArray data = restTemplate.exchange(url1, HttpMethod.GET, r, JSONObject.class).getBody().getJSONArray("data");
        List<Map<String, Object>> list = new ArrayList<>();
        if(data.isEmpty()){
            return  list;
        }
        for (int i = 0; i < data.size(); i++) {
            JSONObject jsonObject = data.getJSONObject(i); // 获取每个元素的 JSONObject 对象
            Map<String, Object> map = jsonObject.toJavaObject(Map.class); // 将 JSONObject 转换为 Map
            list.add(map); // 将 Map 添加到 List 中
        }
        return list;
    }

    /**
     *
     * @param sign 0本系统，1外来系统
     * @return
     */
    public String getNumber(String sign) {
        String requestId = UUIDGenerator.getUUID();
        String number1="";
        Boolean isLocked = redisLockUtil.lock("redis_eventCode_lock_serialNum", requestId, 6L);
        if (isLocked){
            log.info("成功获取redis_eventCode_lock_serialNum锁");
            String b="B";
            if("1".equals(sign)){
                b="Y";
            }
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
            String date = sdf.format(new Date());

            String number = date + "0001";
            Timestamp startTimestamp = new Timestamp(getStartTime().getTime());
            Timestamp endTimestamp = new Timestamp(getEndTime().getTime());
            String count = theMapRepository.getNumber(startTimestamp,endTimestamp);
            String s = number.substring(0, number.length() - count.length());
            number1 =b+s + (Integer.parseInt(count) + 1);
            redisLockUtil.releaseLock("redis_distributed_lock_serialNum", requestId);
            log.info("成功释放redis_distributed_lock_serialNum锁");
        }else {
            log.info("获取redis_eventCode_lock_serialNum锁失败，进行休眠");
            try {
                Thread.sleep(10000);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        return number1;
    }


    private Date getStartTime() {
        Calendar todayStart = Calendar.getInstance();
        todayStart.set(Calendar.SECOND, 0);
        todayStart.set(Calendar.MINUTE, 0);
        todayStart.set(Calendar.HOUR_OF_DAY, 0);
        todayStart.set(Calendar.MILLISECOND, 0);
        return todayStart.getTime();
    }

    private Date getEndTime() {
        Calendar todayEnd = Calendar.getInstance();
        todayEnd.set(Calendar.SECOND, 59);
        todayEnd.set(Calendar.MINUTE, 59);
        todayEnd.set(Calendar.HOUR_OF_DAY, 23);
        todayEnd.set(Calendar.MILLISECOND, 999);
        return todayEnd.getTime();
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void dockingOtherSystem(OtherSystemInfoVo otherSystemInfoVo) throws Exception{
        MultipartFile file = otherSystemInfoVo.getFile();

        //获取文件名称
        String fileName = file.getOriginalFilename();
        //获取文件上传的本地路径
        String dateDir = new SimpleDateFormat("/yyyy/MM/dd").format(new Date());
        String savePath = localDir + dateDir;
        //构建文件
        assert fileName != null;
        //上传文件
        String realFileName = uploadFile(fileName, savePath, file);
        //构建实体类
        AttachmentInfoEntity attachmentInfoEntity = buildAttachment(fileName, dateDir, realFileName);
        //保存附件到数据库
        int flag = 0;
        if (ObjectUtils.isNotEmpty(attachmentInfoEntity)) {
            flag = attachmentInfoService.singleSave(attachmentInfoEntity);
        }
        if (flag == 1) {
            ThematicMap thematicMap = new ThematicMap();
            thematicMap.setReleaseDate(new Date());
            thematicMap.setId(UUIDGenerator.getUUID());
            thematicMap.setCreateTime(new Date());
            thematicMap.setDelFlag(YNEnum.N.toString());
            thematicMap.setReleaseStatus("0");
            thematicMap.setPictureFile(attachmentInfoEntity.getAttachId());
            thematicMap.setNumber(getNumber("1"));
            if (FxfzConstants.FXFZ_DZZH.equals(otherSystemInfoVo.getFlag())) {
                thematicMap.setReleaseColumn("评估类-地质灾害危险性分布图");
            } else {

            }
            BeanUtils.copyProperties(otherSystemInfoVo, thematicMap);
            theMapRepository.save(thematicMap);
        }
    }

    private String uploadFile(String fileName, String savePath,MultipartFile multipartFile) throws IOException {
        // 获取文件的后缀名
        assert fileName != null;
        String preFileName = fileName.substring(0,fileName.lastIndexOf("."));
        // .jpg  .pdf  .txt  .docs
        String fileType = fileName.substring(fileName.lastIndexOf("."));
        // 拼文件名  真实的文件名称
        String realFileName = preFileName + "_"  + System.currentTimeMillis() + fileType;
        //判断文件夹是否存在如果不存在则创建
        if(!new File(savePath).exists()){
            new File(savePath).mkdirs();
        }
        File file = new File(savePath, realFileName);
        multipartFile.transferTo(file);
        return realFileName;
    }

    private AttachmentInfoEntity buildAttachment(String fileName, String dateDir, String realFileName) {
        AttachmentInfoEntity attachmentInfoEntity = new AttachmentInfoEntity();
        attachmentInfoEntity.setAttachId(StringUtils.buildPrimaryId());
        attachmentInfoEntity.setAttachName(fileName);
        attachmentInfoEntity.setAttachPath( dateDir + "/" + realFileName);
        attachmentInfoEntity.setFileDirId(localDir);
        attachmentInfoEntity.setIsValid("1");
        attachmentInfoEntity.setIsCompleted("1");
        return attachmentInfoEntity;
    }
}
